#include<stdio.h>
#include<stdlib.h>
#define len(array) sizeof(array)/sizeof(*array)
void MergeList(int *la, int *lb, int len_a, int len_b);
int compar(const void *e1, const void *e2);

int main (){
    int a [] = {1,2,4,5,7};
    int b [] = {2,4,2,23,41,352,-12};
    qsort(a, len(a), sizeof(*a), compar);
    qsort(b, len(b), sizeof(*b), compar);
    MergeList(a, b, len(a), len(b));
    return 0;
}

int compar(const void *e1, const void *e2){
    return (*(int *)e1 - *(int *)e2);
}

//两数组归并排序
void MergeList(int *la, int *lb, int len_a, int len_b){
    int lc [len_a+len_b];
    int ia, ib, ic;
    ia = ib = ic = 0;
    while(ia<len_a && ib<len_b){
        if(la[ia]<=lb[ib]){
            lc[ic] = la[ia];
            ic++;
            ia++;
        }else{
            lc[ic] = lb[ib];
            ic++;
            ib++;
        }
    }
    while(ia<len_a){
        lc[ic] = la[ia];
        ic++;
        ia++;
    }
    while(ib<len_b){
        lc[ic] = lb[ib];
        ic++;
        ib++;
    }
    for(int i=0;i<len(lc);i++){
        printf("%d ", lc[i]);
    }
}